
var title = document.querySelector('#title')
var todolist = document.querySelector('#todolist')
title.onkeydown = function (e) {
    console.log(e)
    var keycode = e.keyCode || e.which
    if (keycode === 13) {
        var li = document.createElement('li')
        todolist.appendChild(li)
        //创建input选框
        var input = document.createElement('input')
        input.type = 'checkbox'
        li.appendChild(input)
        var p = document.createElement('p')
        p.innerText = this.value;
        li.appendChild(p)
        var a = document.createElement('a')
        a.innerText = '-'
        a.setAttribute('href', 'javascript:;')
        li.appendChild(a)
        this.value = ''
        count()
    }
}
var donelist = document.querySelector('#donelist')
click(todolist, donelist)
click(donelist, todolist)
function click(ele, targetNode) {
    console.log(ele)
    console.log(targetNode)
    ele.onclick = function (e) {
        console.log(e.target)
        if (e.target.tagName === 'INPUT' && e.target.getAttribute('type') === 'checkbox') {
            targetNode.appendChild(e.target.parentElement)
            count()
        } else if (e.target.tagName === 'P') {
            var str = '<input type="text" value="' + e.target.innerText + '">'
            e.target.innerHTML = str
            e.target.firstElementChild.onblur = function () {
                e.target.innerText = this.value
            }
        } else if (e.target.tagName === 'A') {
            if (confirm("你确定要删除吗？")) {
                e.target.parentElement.parentElement.removeChild(e.target.parentElement)
                count()
            }
        }

    }
}
function count() {
    document.querySelector('#todocount').innerText = todolist.children.length
    document.querySelector('#donecount').innerText = donelist.children.length
}



const ip = document.querySelector('#ipv4')
const area = document.querySelector('#addr')
ks2()
async function ks2() {
    const res = await pAjax({
        url: '/ten',
        dataType: 'json'
    })
    console.log(res)
    ip.innerText = res.beginip
    area.innerText = res.country + res.area
}